package com.weixing.mall.provider.controller.admin;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.weixing.mall.base.wrapper.Result;
import com.weixing.mall.base.wrapper.ResultUtil;
import com.weixing.mall.core.annotation.NoNeedAccess;
import com.weixing.mall.core.support.BaseController;
import com.weixing.mall.core.support.auth.SysAuth;
import com.weixing.mall.core.support.auth.SysInfo;
import com.weixing.mall.provider.model.domain.InDepotBillProduct;
import com.weixing.mall.provider.model.domain.OutDepotBillProduct;
import com.weixing.mall.provider.model.dto.ChgDepotNumDto;
import com.weixing.mall.provider.service.IOutDepotBillProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName AdminOutDepotBillProductController
 * @Description TODO <br/>
 * @Author gjq
 * @Modified By:
 * @Date 2019/10/24
 * @Version 1.0
 **/
@RequestMapping("outDepotBillProduct")
@RestController
@Api(value = "出库单关联商品Api",tags = "出库单关联商品")
public class OutDepotBillProductController extends BaseController {

    @Autowired
    private IOutDepotBillProductService outDepotBillProductService;


    @ApiOperation(value = "根据入库单id查找关联商品list")
    @GetMapping("list/{inDepotId}")
    @NoNeedAccess
    public Result list(@PathVariable Long inDepotId){
        List<OutDepotBillProduct> list=  outDepotBillProductService.list(new QueryWrapper<OutDepotBillProduct>().eq("out_depot_id",inDepotId));
        return ResultUtil.success(list);
    }
    @ApiOperation(value = "根据关联表id修改出库关联商品数量")
    @PostMapping("outDepotChgNum")
    public Result outDepotChgNum(@SysInfo SysAuth auth, ChgDepotNumDto chgDepotNumDto){
        outDepotBillProductService.outDepotChgNum(chgDepotNumDto,auth.getUid());
        return ResultUtil.success();
    }

    /*
     * 删除时判定是否已经出库在前台进行判定
     *
     * */
    @ApiOperation(value = "删除")
    @GetMapping("del/{id}")
    public Result del(@PathVariable Long id){

        outDepotBillProductService.removeById(id);

        return ResultUtil.success();
    }
}
